package com.example.administrator.testpersionn.wxapi;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;

import com.example.administrator.testpersionn.R;
import com.example.administrator.out1.adapter.HomePagerRecyclerViewAdapter;
import com.zinc.jrecycleview.JRecycleView;
import com.zinc.jrecycleview.adapter.JRefreshAndLoadMoreAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class JrecyclerViewActivity extends AppCompatActivity {

    @BindView(R.id.jRecyclerView)
    JRecycleView jRecyclerView;
    List<String> list=new ArrayList<>();
    JRefreshAndLoadMoreAdapter mAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jrecycler_view);
        ButterKnife.bind(this);
        for (int i = 0; i < 50; i++) {
            list.add("position"+i);
        }
        // 只需将你所编写的 Adapter 替换此处的 "YourAdapter" 传入 JRefreshAndLoadMoreAdapter
         mAdapter = new JRefreshAndLoadMoreAdapter(this, new HomePagerRecyclerViewAdapter(this,list));

// 设置下拉刷新监听
        mAdapter.setOnRefreshListener(new JRefreshAndLoadMoreAdapter.OnRefreshListener() {
            @Override
            public void onRefreshing() {
               list.add("下拉的"+list.size()+"条");
                mAdapter.setRefreshComplete();
                //关闭下拉刷新
                mAdapter.setIsOpenRefresh(false);
            }
        });

// 设置加载更多监听
        mAdapter.setOnLoadMoreListener(new JRefreshAndLoadMoreAdapter.OnLoadMoreListener() {
            @Override
            public void onLoading() {
                //do something for load more data
                list.add("加载更多的"+list.size()+"条");
                mAdapter.setIsOpenLoadMore(false);
            }
        });

        jRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        jRecyclerView.setAdapter(mAdapter);



    }
}
